# Reverse-engineering a learning management system

For most proprietary services, the API is internal and unknown. In order to
integrate it into polyglot, this part will need to be reverse-engineered.

_For adding a backend the API is already known, see the [backend
guide](adding-a-backend.md)_

To begin the reverse-engineering process, network traffic needs to be captured
from the original service. There are a number of techniques for this; one is
bundled with Firefox.

For this, open the network inspector in Firefox. Click settings and enable
"persistent logging". Then, use the learning management system as normal,
beginning with authentication and exercising each path of interest. Once this
is complete, return to the network inspector. Right-click and select "Save all
as HAR". A HAR file will be saved containing all of the relevant traffic, ready
for analysis.

To analyse, use a [free HAR viewer](http://www.softwareishard.com/har/viewer/).

As patterns emerge, write down your work, and write code to implement the path
needed. _Do this work locally_. I cannot stress this enough -- do **not**
debug code with production data. Mock up the data from the network capture if
you have to. Do **not** overload the services that you are reverse-engineering
-- hogging bandwidth will draw attention to yourself and cause you (and
polyglot in general) to lose the goodwill of the service in question. Don't be
that guy.

Once you have sense for the protocol, begin writing a backend by making a copy
of the dummy backend. Remove methods that your backend cannot support, and
comment those that will be implemented (by you) but not yet. Begin filling in
the backend with methods implementing the reverse-engineered methods. The
module requests will be your friend; it is used throughout polyglot. If there
is no sane API to work with and you find yourself resorting to scraping HTML,
the lxml module may be used for parsing. See the [backend
guide](adding-a-backend.md) for general notes on writing a backend the polyglot
way.

Once everything is wired up and working, don't celebrate yet -- write-only code
is no fun! Code written directly from reverse-engineering results tends to be
incredibly messy, but it isn't hard to get it up to maintainable standards.
Even if you maintain the code yourself after it is merged in polyglot (we
encourage it!), still try to clean it up. Your future self will thank you.

The Haiku (PowerSchool Learning) backend was reverse-engineered with these
techniques and may be a useful reference, including the git history.
